package cn.wzvtc.solf14.Service;

import cn.wzvtc.solf14.JavaBean.Course;
import cn.wzvtc.solf14.Repository.CourseRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Created by Administrator on 2016/3/18.
 */
@Service
public class CourseService {

    @Autowired
    CourseRepository courseRepository;

    public List getCourse(){

        Course course;
        ArrayList list = new ArrayList();
        for(int i=0;i<20;i++){
            course = new Course();
            course.setAddr("505");
            course.setDay(4);
            course.setStartTime(1);
            course.setLength(2);
            course.setName("口才与思维"+i);
            course.setT("刘小方");
            list.add(course);
        }

        return list;
    }

    public String insert(String addr, String t, String name, int day, int startTime, int length, int week, String clazz){
        Course course = new Course();
        course.setT(t);
        course.setName(name);
        course.setDay(day);
        course.setAddr(addr);
        course.setLength(length);
        course.setStartTime(startTime);
        course.setWeek(week);
        course.setClazz(clazz);
        course.setId(UUID.randomUUID().toString());
        courseRepository.save(course);
        return "OK";
    }

    public List findByWeekAndClazz(int week, String clazz){
        return courseRepository.findByWeekAndClazz(week, clazz);
    }


}
